package com.tesis_2.Utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;


import com.example.tesis_2.R;
import com.tesis_2.BL.BLRestaurants;
import com.tesis_2.DA.DAOUtils;
import com.tesis_2.DA.ImageDownloader;
import com.tesis_2.MO.Restaurant;
 
public class RestaurantsCategoryImageAdapter extends BaseAdapter {
	private Context context;
	
 
	public RestaurantsCategoryImageAdapter(Context context) {
		this.context = context;
		
	}
 
	public View getView(int position, View convertView, ViewGroup parent) {
 
		LayoutInflater inflater = (LayoutInflater) context
			.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
 		View gridView;
 
		if (convertView == null) {
			
			gridView = new View(context);
			
			// get layout from mobile.xml
			gridView = inflater.inflate(R.layout.activity_restaurants_category_item, null);
			
			//nombre del rest
			TextView textView = (TextView) gridView
					.findViewById(R.id.txvNombre_restaurant_category_item);
			textView.setText( ((Restaurant) (getItem(position))).getName());
			textView.setText( ((Restaurant) (getItem(position))).getName());
			
			//tipo de cocina
			textView = (TextView) gridView
					.findViewById(R.id.txvDesc_restaurant_category_item);
			textView.setText( ((Restaurant) (getItem(position))).getCuisine()+ "cuisine.");
			
			//score
			RatingBar rb = (RatingBar) gridView.findViewById(R.id.rbCalificacion_restaurant_category_item);
			rb.setRating(((Restaurant) (getItem(position))).getScore());
			
			// set image based on selected text
			ImageView imageView = (ImageView) gridView
					.findViewById(R.id.imgRest_restaurant_category_item);
			//ImageDownloader mDownload = new ImageDownloader();
			
			//mDownload.download(DAOUtils.getServer()+"/assets/restaurants/"+ ((Restaurant) (getItem(position))).getId()  +"/small/" + ((Restaurant) (getItem(position))).getPhoto(), imageView);
			//imageView.setScaleType(ImageView.ScaleType.CENTER);
			
		} else {
			//Toast.makeText(context, "null", 2).show();
			gridView = (View) convertView;
		}
 
		return gridView;
	}
 
	@Override
	public int getCount() {
		return BLRestaurants.getLsRest().size();
	}
 
	@Override
	public Object getItem(int position) {
		return BLRestaurants.getLsRest().get(position);
	}
 
	@Override
	public long getItemId(int position) {
		return BLRestaurants.getLsRest().get(position).getId();
	}
 
}
